<template>
  <teleport to="#show">
    <div class="modal d-block" tabindex="-1" v-if="visible">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title">{{ title }}</h5>
            <button
              type="button"
              class="btn-close"
              data-bs-dismiss="modal"
              aria-label="Close"
              @click="toClose"
            ></button>
          </div>
          <div class="modal-body">
           <slot></slot>
          </div>
          <div class="modal-footer">
            <button
              type="button"
              class="btn btn-secondary"
              data-bs-dismiss="modal"
              @click="toClose"
            >
              取消
            </button>
            <button type="button" class="btn btn-primary" @click="toConfirm">
              确定
            </button>
          </div>
        </div>
      </div>
    </div>
  </teleport>
</template>

<script lang="ts">
import { defineComponent, onUnmounted } from "vue";
import useDOMCreate from "@/hooks/useDOMCreate";

export default defineComponent({
  emits: ["modal-on-close", "modal-on-confirm"],
  props: {
    title:String,
    visible: { type: Boolean, default: false },
  },
  setup(props, context) {
    const toClose = () => {
      context.emit("modal-on-close");
    };
    const toConfirm = () => {
      context.emit("modal-on-confirm");
    };
    useDOMCreate("show");
    return { toClose, toConfirm };
  },
});
</script>

<style scoped></style>
